//
//  MoKuaiGuanLiViewController.m
//  ShouKuang
//
//  Created by CodeYY on 2019/6/3.
//  Copyright © 2019 CodeYY. All rights reserved.
//

#import "MoKuaiGuanLiViewController.h"
#import "GeRenXinXiViewController.h"
@interface MoKuaiGuanLiViewController ()<UITableViewDataSource,UITableViewDelegate>
@property(nonatomic, strong)UITableView *tableView;
@property(nonatomic, strong)NSMutableArray *dataArray;
@end

@implementation MoKuaiGuanLiViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.dataArray = [NSMutableArray arrayWithArray:@[@"",@"",@"",@"",@"",@"",@"",@"",@""]];
    
    // 导航栏
    [self initNavBar];
    [self initTableView];
    // contView
    
    
    // Do any additional setup after loading the view.
}

-(void)initNavBar
{
    WEAKSELF
    UIButton *leftBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [leftBtn setImage:[UIImage imageNamed:@"nav_back_red"] forState:UIControlStateNormal];
    [leftBtn setTitle:@"返回" forState:UIControlStateNormal];
    [leftBtn setTitleColor:YYRGB(129, 129, 129) forState:UIControlStateNormal];
    [leftBtn jk_setImagePosition:LXMImagePositionLeft spacing:5];
    [[leftBtn rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(id x) {
        [weakSelf.navigationController popViewControllerAnimated:YES];
    }];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:leftBtn];
    
    self.title = @"模块管理员";
    
    UIButton *searchBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [[searchBtn rac_signalForControlEvents:UIControlEventTouchUpInside]subscribeNext:^(UIButton *x) {

    }];
    [searchBtn setImage:[UIImage imageNamed:@"home_tj"] forState:UIControlStateNormal];
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:searchBtn];
}

- (void)initTableView
{
    WEAKSELF
    UITableView *tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
    _tableView = tableView;
    tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    tableView.rowHeight = 70;
    [self.view addSubview:tableView];
    //    tableView.backgroundColor = [UIColor clearColor];
    [tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view);
        make.right.equalTo(self.view);
        make.top.offset(70);
        make.bottom.equalTo(self.view);
    }];
    
    tableView.delegate = self;
    tableView.dataSource = self;
    tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"UITableViewCells"];

}


#pragma mark -delegate

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
   
    return self.dataArray.count;
}

-(BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
    return YES;
}



- (NSArray*)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(nonnull NSIndexPath *)indexPath
{
    __weak typeof(self) weakSelf = self;
    // delete action
    UITableViewRowAction *deleteAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleNormal title:@"删除" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath)
                                          {
                                              [tableView setEditing:NO animated:YES];  // 这句很重要，退出编辑模式，隐藏左滑菜单
                                              [weakSelf.dataArray removeObjectAtIndex:indexPath.row];
                                              [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone];
                                          }];
    deleteAction.backgroundColor = [UIColor redColor];
    
    return @[deleteAction];
}


-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"UITableViewCells" forIndexPath:indexPath];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    [cell.subviews enumerateObjectsUsingBlock:^(__kindof UIView * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        [obj removeFromSuperview];
    }];
    
   
        UIImageView *img = [UIImageView new];
        [cell addSubview:img];
        [img mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.offset(16);
            make.centerY.offset(0);
            make.size.mas_equalTo(CGSizeMake(35, 35));
        }];
        img.layer.cornerRadius = 35/2;
        img.layer.masksToBounds = YES;
        
        UILabel *titleLab = [UILabel new];
        [cell addSubview:titleLab];
        [titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(img.mas_right).offset(10);
            make.centerY.offset(0);
        }];
        titleLab.textColor = [UIColor lightGrayColor];
        
        UILabel *contentLab = [UILabel new];
        [cell addSubview:contentLab];
        [contentLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.offset(-16);
            make.centerY.offset(0);
        }];
        contentLab.textColor = [UIColor darkGrayColor];
        
        // 赋值
        img.backgroundColor = [UIColor greenColor];
        

        titleLab.text = @"dfasf";
        contentLab.text = @"模块管理员";

    UIView *line  = [UIView new];
    [cell addSubview:line];
    [line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.offset(0);
        make.height.mas_equalTo(1);
    }];
    line.backgroundColor = [UIColor darkGrayColor];
    return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
        GeRenXinXiViewController *vc = [GeRenXinXiViewController new];
        [self.navigationController pushViewController:vc animated:YES];
    
}

@end
